package com.ktgj.customer.controller;

import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.customer.domain.BusinessOrder;
import com.ktgj.customer.service.IBusinessOrderService;
import com.ktgj.pay.api.RemotePayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

@ControllerAdvice
@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private IBusinessOrderService iBusinessOrderService;

    @Autowired
    private RemotePayService remotePayService;

    @PostMapping("/payapplet")
    public AjaxResult PayApplet() throws Exception {
        //BusinessOrder businessOrder = iBusinessOrderService.selectBusinessOrderById(orderId);
        Map<String, String> payParam = remotePayService.getWechatJSAPIPayParam("oG5Z_4jpom9pM1TvhCB4I7ROD4YA",
                new BigDecimal(0.01), "20210902030346117",
                "http://39.106.54.2:8080/WXPay/orderResult").getData();
        return AjaxResult.success(payParam);
    }

    /**
     * 生成微信支付
     *
     * @param orderId
     * @return
     */
    @GetMapping("createNative/{orderId}")
    public AjaxResult createNative(@PathVariable Long orderId) {
        BusinessOrder businessOrder = iBusinessOrderService.selectBusinessOrderById(orderId);
        Map map = remotePayService.createNative(orderId, businessOrder.getAddress(), businessOrder.getOrdernum(), businessOrder.getPrice()).getData();
        return AjaxResult.success(map);
    }

}
